<!--********************************************************************
* Copyright© 2000 - 2018 SuperMap Software Co.Ltd. All rights reserved.
*********************************************************************-->
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title data-i18n="resources.title_Scatter"></title>
    <script type="text/javascript" src="../js/include-web.js"></script>
</head>
<body style=" margin: 0;overflow: hidden;background: #fff;width: 100%;height:100%;position: absolute;top: 0;">
<div id="map" style="margin:0 auto;width: 100%;height: 100%"></div>
<script type="text/javascript" include="echarts" src="../../dist/leaflet/include-leaflet.js"></script>
<script type="text/javascript">
    var host = window.isLocal ? window.server : "http://support.supermap.com.cn:8090";
    var map, resultLayer, url = host + "/iserver/services/map-world/rest/maps/世界地图_Gray";
    var url2 = host + "/iserver/services/map-china400/rest/maps/China";
    map = L.map('map', {
        crs: L.CRS.EPSG4326,
        center: [39.905, 116.402],
        maxZoom: 18,
        zoom: 5
    });
    L.supermap.tiledMapLayer(url).addTo(map);
    var pollution = [
        resources.text_mildPollution,
        resources.text_moderatePollution,
        resources.text_heavyPollution,
        resources.text_severePollution,
        resources.text_great,
        resources.text_good
    ];
    var dataBJ = [
        [1, 55, 9, 56, 0.46, 18, 6, pollution[5]],
        [2, 25, 11, 21, 0.65, 34, 9, pollution[4]],
        [3, 56, 7, 63, 0.3, 14, 5, pollution[5]],
        [4, 33, 7, 29, 0.33, 16, 6, pollution[4]],
        [5, 42, 24, 44, 0.76, 40, 16, pollution[4]],
        [6, 82, 58, 90, 1.77, 68, 33, pollution[5]],
        [7, 74, 49, 77, 1.46, 48, 27, pollution[5]],
        [8, 78, 55, 80, 1.29, 59, 29, pollution[5]],
        [9, 267, 216, 280, 4.8, 108, 64, pollution[2]],
        [10, 185, 127, 216, 2.52, 61, 27, pollution[1]],
        [11, 39, 19, 38, 0.57, 31, 15, pollution[4]],
        [12, 41, 11, 40, 0.43, 21, 7, pollution[4]],
        [13, 64, 38, 74, 1.04, 46, 22, pollution[5]],
        [14, 108, 79, 120, 1.7, 75, 41, pollution[0]],
        [15, 108, 63, 116, 1.48, 44, 26, pollution[0]],
        [16, 33, 6, 29, 0.34, 13, 5, pollution[4]],
        [17, 94, 66, 110, 1.54, 62, 31, pollution[5]],
        [18, 186, 142, 192, 3.88, 93, 79, pollution[1]],
        [19, 57, 31, 54, 0.96, 32, 14, pollution[5]],
        [20, 22, 8, 17, 0.48, 23, 10, pollution[4]],
        [21, 39, 15, 36, 0.61, 29, 13, pollution[4]],
        [22, 94, 69, 114, 2.08, 73, 39, pollution[5]],
        [23, 99, 73, 110, 2.43, 76, 48, pollution[5]],
        [24, 31, 12, 30, 0.5, 32, 16, pollution[4]],
        [25, 42, 27, 43, 1, 53, 22, pollution[4]],
        [26, 154, 117, 157, 3.05, 92, 58, pollution[1]],
        [27, 234, 185, 230, 4.09, 123, 69, pollution[3]],
        [28, 160, 120, 186, 2.77, 91, 50, pollution[1]],
        [29, 134, 96, 165, 2.76, 83, 41, pollution[0]],
        [30, 52, 24, 60, 1.03, 50, 21, pollution[5]],
        [31, 46, 5, 49, 0.28, 10, 6, pollution[4]]
    ];

    var dataGZ = [
        [1, 26, 37, 27, 1.163, 27, 13, pollution[4]],
        [2, 85, 62, 71, 1.195, 60, 8, pollution[5]],
        [3, 78, 38, 74, 1.363, 37, 7, pollution[5]],
        [4, 21, 21, 36, 0.634, 40, 9, pollution[4]],
        [5, 41, 42, 46, 0.915, 81, 13, pollution[4]],
        [6, 56, 52, 69, 1.067, 92, 16, pollution[5]],
        [7, 64, 30, 28, 0.924, 51, 2, pollution[5]],
        [8, 55, 48, 74, 1.236, 75, 26, pollution[5]],
        [9, 76, 85, 113, 1.237, 114, 27, pollution[5]],
        [10, 91, 81, 104, 1.041, 56, 40, pollution[5]],
        [11, 84, 39, 60, 0.964, 25, 11, pollution[5]],
        [12, 64, 51, 101, 0.862, 58, 23, pollution[5]],
        [13, 70, 69, 120, 1.198, 65, 36, pollution[5]],
        [14, 77, 105, 178, 2.549, 64, 16, pollution[5]],
        [15, 109, 68, 87, 0.996, 74, 29, pollution[0]],
        [16, 73, 68, 97, 0.905, 51, 34, pollution[5]],
        [17, 54, 27, 47, 0.592, 53, 12, pollution[5]],
        [18, 51, 61, 97, 0.811, 65, 19, pollution[5]],
        [19, 91, 71, 121, 1.374, 43, 18, pollution[5]],
        [20, 73, 102, 182, 2.787, 44, 19, pollution[5]],
        [21, 73, 50, 76, 0.717, 31, 20, pollution[5]],
        [22, 84, 94, 140, 2.238, 68, 18, pollution[5]],
        [23, 93, 77, 104, 1.165, 53, 7, pollution[5]],
        [24, 99, 130, 227, 3.97, 55, 15, pollution[5]],
        [25, 146, 84, 139, 1.094, 40, 17, pollution[0]],
        [26, 113, 108, 137, 1.481, 48, 15, pollution[0]],
        [27, 81, 48, 62, 1.619, 26, 3, pollution[5]],
        [28, 56, 48, 68, 1.336, 37, 9, pollution[5]],
        [29, 82, 92, 174, 3.29, 0, 13, pollution[5]],
        [30, 106, 116, 188, 3.628, 101, 16, pollution[0]],
        [31, 118, 50, 0, 1.383, 76, 11, pollution[0]]
    ];

    var dataSH = [
        [1, 91, 45, 125, 0.82, 34, 23, pollution[5]],
        [2, 65, 27, 78, 0.86, 45, 29, pollution[5]],
        [3, 83, 60, 84, 1.09, 73, 27, pollution[5]],
        [4, 109, 81, 121, 1.28, 68, 51, pollution[0]],
        [5, 106, 77, 114, 1.07, 55, 51, pollution[0]],
        [6, 109, 81, 121, 1.28, 68, 51, pollution[0]],
        [7, 106, 77, 114, 1.07, 55, 51, pollution[0]],
        [8, 89, 65, 78, 0.86, 51, 26, pollution[5]],
        [9, 53, 33, 47, 0.64, 50, 17, pollution[5]],
        [10, 80, 55, 80, 1.01, 75, 24, pollution[5]],
        [11, 117, 81, 124, 1.03, 45, 24, pollution[0]],
        [12, 99, 71, 142, 1.1, 62, 42, pollution[5]],
        [13, 95, 69, 130, 1.28, 74, 50, pollution[5]],
        [14, 116, 87, 131, 1.47, 84, 40, pollution[0]],
        [15, 108, 80, 121, 1.3, 85, 37, pollution[0]],
        [16, 134, 83, 167, 1.16, 57, 43, pollution[0]],
        [17, 79, 43, 107, 1.05, 59, 37, pollution[5]],
        [18, 71, 46, 89, 0.86, 64, 25, pollution[5]],
        [19, 97, 71, 113, 1.17, 88, 31, pollution[5]],
        [20, 84, 57, 91, 0.85, 55, 31, pollution[5]],
        [21, 87, 63, 101, 0.9, 56, 41, pollution[5]],
        [22, 104, 77, 119, 1.09, 73, 48, pollution[0]],
        [23, 87, 62, 100, 1, 72, 28, pollution[5]],
        [24, 168, 128, 172, 1.49, 97, 56, pollution[1]],
        [25, 65, 45, 51, 0.74, 39, 17, pollution[5]],
        [26, 39, 24, 38, 0.61, 47, 17, pollution[4]],
        [27, 39, 24, 39, 0.59, 50, 19, pollution[4]],
        [28, 93, 68, 96, 1.05, 79, 29, pollution[5]],
        [29, 188, 143, 197, 1.66, 99, 51, pollution[1]],
        [30, 174, 131, 174, 1.55, 108, 50, pollution[1]],
        [31, 187, 143, 201, 1.39, 89, 53, pollution[1]]
    ];

    var schema = [
        {name: 'date', index: 0, text: resources.text_day2},
        {name: 'AQIindex', index: 1, text: resources.text_AQIindex},
        {name: 'PM25', index: 2, text: resources.text_PM25},
        {name: 'PM10', index: 3, text: resources.text_PM10},
        {name: 'CO', index: 4, text: resources.text_CO},
        {name: 'NO2', index: 5, text: resources.text_NO2},
        {name: 'SO2', index: 6, text: resources.text_SO2}
    ];

    var dataMap = {"北京市": dataBJ, "广州市": dataGZ, "上海市": dataSH};
    var colorMap = {"北京市": '#dd4444', "广州市": '#fec42c', "上海市": '#80F1BE'};
    var itemStyle = {
        normal: {
            opacity: 0.8,
            shadowBlur: 10,
            shadowOffsetX: 0,
            shadowOffsetY: 0,
            shadowColor: 'rgba(0, 0, 0, 0.5)'
        }
    };
    option = {
        backgroundColor: '#404a59',
        color: [
            '#dd4444'
        ],
        legend: {
            y: 'top',
            data: ['北京市'],
            textStyle: {
                color: '#fff',
                fontSize: 16
            },
            selectedMode: 'single'
        },
        grid: {
            x: '10%',
            x2: 150,
            y: '18%',
            y2: '10%'
        },
        tooltip: {
            padding: 10,
            backgroundColor: '#222',
            borderColor: '#777',
            borderWidth: 1,
            formatter: function (obj) {
                var value = obj.value;
                return '<div style="border-bottom: 1px solid rgba(255,255,255,.3); font-size: 18px;padding-bottom: 7px;margin-bottom: 7px">'
                    + obj.seriesName + ' ' + resources.text_day1 + value[0] + resources.text_day2
                    + value[7]
                    + '</div>'
                    + schema[1].text + '：' + value[1] + '<br>'
                    + schema[2].text + '：' + value[2] + '<br>'
                    + schema[3].text + '：' + value[3] + '<br>'
                    + schema[4].text + '：' + value[4] + '<br>'
                    + schema[5].text + '：' + value[5] + '<br>'
                    + schema[6].text + '：' + value[6] + '<br>';
            }
        },
        xAxis: {
            type: 'value',
            name: resources.text_data,
            nameGap: 16,
            nameTextStyle: {
                color: '#fff',
                fontSize: 14
            },
            max: 31,
            splitLine: {
                show: false
            },
            axisLine: {
                lineStyle: {
                    color: '#eee'
                }
            }
        },
        yAxis: {
            type: 'value',
            name: resources.text_AQIindex,
            nameLocation: 'end',
            nameGap: 20,
            nameTextStyle: {
                color: '#fff',
                fontSize: 16
            },
            axisLine: {
                lineStyle: {
                    color: '#eee'
                }
            },
            splitLine: {
                show: false
            }
        },
        visualMap: [
            {
                left: 'right',
                top: '5%',
                dimension: 2,
                min: 0,
                max: 250,
                itemWidth: 20,
                itemHeight: 80,
                calculable: true,
                precision: 0.1,
                text: [resources.text_roundSize],
                textGap: 20,
                textStyle: {
                    color: '#fff'
                },
                inRange: {
                    symbolSize: [10, 70]
                },
                outOfRange: {
                    symbolSize: [10, 70],
                    color: ['rgba(255,255,255,.2)']
                },
                controller: {
                    inRange: {
                        color: ['#dd4444']
                    },
                    outOfRange: {
                        color: ['#444']
                    }
                }
            },
            {
                left: 'right',
                bottom: '5%',
                dimension: 6,
                min: 0,
                max: 50,
                itemHeight: 80,
                itemWidth: 20,
                calculable: true,
                precision: 0.1,
                text: [resources.text_SO2text],
                textGap: 20,
                textStyle: {
                    color: '#fff'
                },
                inRange: {
                    colorLightness: [1, 0.5]
                },
                outOfRange: {
                    color: ['rgba(255,255,255,.2)']
                },
                controller: {
                    inRange: {
                        color: ['#dd4444']
                    },
                    outOfRange: {
                        color: ['#444']
                    }
                }
            }
        ],
        series: [
            {
                name: '北京市',
                type: 'scatter',
                itemStyle: itemStyle,
                data: dataBJ
            }
        ]
    };
    var div = L.DomUtil.create('div');
    var chart = echarts.init(div, '', {
        width: 450,
        height: 350
    });
    chart.setOption(option);
    var control = L.control({position: 'topright'});
    control.onAdd = function (map) {
        return chart.getDom();
    };
    control.addTo(map);
    query();

    function query() {
        clearLayer();
        var param = new SuperMap.QueryBySQLParameters({
            queryParams: [{
                name: "China_ProCenCity_pt@China",
                attributeFilter: "NAME = '广州市' or NAME = '上海市'"
            }, {
                name: "China_Capital_pt@China",
                attributeFilter: "NAME = '北京市'"
            }]
        });

        L.supermap
            .queryService(url2)
            .queryBySQL(param, function (serviceResult) {
                serviceResult.result.recordsets.map(function (record) {
                    resultLayer = L.geoJSON(record.features, {
                        coordsToLatLng: function (coords) {
                            var latlng = L.CRS.EPSG3857.unproject(L.point(coords[0], coords[1]));
                            latlng.alt = coords[2];
                            return latlng;
                        },
                    }).on('click', function (e) {
                        var city = e.layer.feature.properties.NAME;
                        chart.setOption({
                            color: [
                                colorMap[city]
                            ],
                            legend: {
                                data: [city]
                            },
                            series: [
                                {
                                    name: city,
                                    type: 'scatter',
                                    itemStyle: itemStyle,
                                    data: dataMap[city]
                                }
                            ],
                            visualMap:[
                                {
                                    inRange: {
                                        symbolSize: [10, 70]
                                    },
                                    outOfRange: {
                                        symbolSize: [10, 70],
                                        color: ['rgba(255,255,255,.2)']
                                    },
                                    controller: {
                                        inRange: {
                                            color: [ colorMap[city] ]
                                        },
                                        outOfRange: {
                                            color: ['#444']
                                        }
                                    }
                                },
                                {
                                    inRange: {
                                        colorLightness: [1, 0.5]
                                    },
                                    outOfRange: {
                                        color: ['rgba(255,255,255,.2)']
                                    },
                                    controller: {
                                        inRange: {
                                            color: [ colorMap[city] ]
                                        },
                                        outOfRange: {
                                            color: ['#444']
                                        }
                                    }
                                }
                            ]
                        });
                        map.panTo(e.latlng);
                    }, {maxWidth: 700}).addTo(map);
                });
            });
    }

    function clearLayer() {
        if (resultLayer) {
            resultLayer.removeFrom(map);
        }
    }

    L.DomEvent
        .on(div, 'mouseover', function () {
            map.dragging.disable();
            map.scrollWheelZoom.disable();
            map.doubleClickZoom.disable();
        })
        .on(div, 'mouseout', function () {
            map.dragging.enable();
            map.scrollWheelZoom.enable();
            map.doubleClickZoom.enable();
        })
</script>
</body>
</html>